package by.wind.drebedengi.asynctask;

import java.util.ArrayList;
import by.wind.drebedengi.database.MyDatabaseHelper;
import by.wind.drebedengi.datalayer.Constants;
import by.wind.drebedengi.datalayer.bean.Record;

import com.j256.ormlite.dao.RuntimeExceptionDao;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.Where;

import android.content.Context;

public class ReportingOutgoingAsyncTask extends ReportingAllAsyncTask {

	public ReportingOutgoingAsyncTask(Context aContext) {
		super(aContext);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected Boolean doInBackground(Long... params) {
		// TODO Auto-generated method stub
		MyDatabaseHelper helper = new MyDatabaseHelper(itsContext);
		RuntimeExceptionDao<Record, Integer> recordDao = helper
				.getRecordDataDao();

		try {
			QueryBuilder<Record, Integer> queryBuilder = recordDao.queryBuilder();
        	Where<Record, Integer> where = queryBuilder.where();
        	where.eq(Record.OPERATION_TYPE, Constants.OPERATION_WASTLE);
        	where.and();
        	where.eq(Record.IS_DUTY, false);
        	queryBuilder.orderBy(Record.OPERATION_DATE, false);
			PreparedQuery<Record> preparedQuery = queryBuilder.prepare();
			itsList = (ArrayList<Record>) recordDao.query(preparedQuery);
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
			helper.close();
			return true;
	}
	
}
